package logic

import (
	"context"
	"product666/userrpc/userrpc"

	"product666/api/internal/svc"
	"product666/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdataLogic {
	return &UpdataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdataLogic) Updata(req *types.UpdataRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	updata, err := l.svcCtx.UserRpc.Updata(l.ctx, &userrpc.UpdataRequest{
		Username: req.Username,
		Password: req.Password,
		Newpass:  req.Newpass,
		Newpasss: req.Newpasss,
		Code:     req.Code,
		Id:       int64(req.ID),
	})
	if err != nil {
		return &types.Response{
			Message:  err.Error(),
			Code:     "500",
			Database: nil,
		}, nil
	}
	return &types.Response{
		Message:  "重置密码成功",
		Code:     "200",
		Database: updata,
	}, nil
}
